﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：董辉
    //
    // 文件名：OrderCover.cs
    // 文件功能描述：订单覆盖率统计
    // 创建标识：董辉 2011-3-29 11:20
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HZ.Supervise.Web.Company
{
    public partial class OrderCover : BasePage
    {
        HZ.Supervise.IBLL.IExecuteContext ibll = HZ.Supervise.BLLFactory.ExecuteContext();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                hidAreaId.Value = CurrentAccount.GetUser().Org.Area.AreaID;

                //开始时间
                txtstarttime.Text = "2011-10-24";//DateTime.Now.AddMonths(-1).ToShortDateString();

                //结束时间
                txtendtime.Text = DateTime.Now.ToShortDateString();

                OrderDataBind();
            }
        }

        /// <summary>
        /// 订单覆盖率数据绑定
        /// 董辉
        /// 2011-3-29 11:21
        /// </summary>
        private void OrderDataBind()
        {
            try
            {

                System.Text.StringBuilder whereAreaId = new System.Text.StringBuilder();

                if (this.hidAreaId.Value != Constants.CURRENT_DEPLOY_AREAID)
                {

                    if (this.hidAreaId.Value.Substring(4, 2) == "00")//市级
                    {

                        whereAreaId.AppendFormat(" and areaid like '{0}%'", this.hidAreaId.Value.Substring(0, 4));

                    }
                    else
                    {

                        whereAreaId.AppendFormat(" and areaid = '{0}'", this.hidAreaId.Value);

                    }

                }
                else
                {

                    whereAreaId.Append(" and 1=1");

                }

                DateTime start = Convert.ToDateTime(txtstarttime.Text);

                DateTime end = Convert.ToDateTime(txtendtime.Text);

                if (end < start)
                {
                    HZ.Web.WebUtil.Alert("后置时间不能小于前置时间！");
                }
                else
                {
                    int t = 0;

                    HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();

                    System.Data.DataTable dt = ibll.GetOrderCover(whereAreaId.ToString(), txtstarttime.Text, txtendtime.Text, 1, 0, out t);

                    this.gv.DataSource = dt;
                    HZ.Supervise.Web.Function.ChangeRate_PS(dt, "Rate");

                    this.gv.DataBind();
                }
            }
            catch (Exception e)
            {
                e.ToString();

                HZ.Web.WebUtil.Alert("时间格式输入错误!");
            }
        }

        /// <summary>
        /// 查询数据事件
        /// 董辉
        /// 2011-3-29 11:18
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            //重新绑定数据
            OrderDataBind();
        }

        /// <summary>
        /// 导出数据事件
        /// 董辉
        /// 2011-3-29 11:20
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            try
            {
                System.Text.StringBuilder whereAreaId = new System.Text.StringBuilder();

                if (this.hidAreaId.Value != Constants.CURRENT_DEPLOY_AREAID)
                {

                    if (this.hidAreaId.Value.Substring(4, 2) == "00")//市级
                    {

                        whereAreaId.AppendFormat(" and areaid like '{0}%'", this.hidAreaId.Value.Substring(0, 4));

                    }
                    else
                    {

                        whereAreaId.AppendFormat(" and areaid = '{0}'", this.hidAreaId.Value);

                    }

                }
                else
                {

                    whereAreaId.Append(" and 1=1");

                }

                DateTime start = Convert.ToDateTime(txtstarttime.Text);

                DateTime end = Convert.ToDateTime(txtendtime.Text);

                if (end < start)
                {
                    HZ.Web.WebUtil.Alert("后置时间不能小于前置时间！");
                }
                else
                {
                    int t = 0;

                    HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();

                    System.Data.DataTable dt = ibll.GetOrderCover(whereAreaId.ToString(), txtstarttime.Text, txtendtime.Text, 1, 0, out t);

                    this.gv.DataSource = dt;
                    HZ.Supervise.Web.Function.ChangeRate_PS(dt, "Rate");

                    this.gv.DataBind();
                    HZ.Excel.ExcelHelper.ExportDataForWeb(dt, gv);
                }

            }
            catch (Exception ex)
            {
                ex.ToString();

                HZ.Web.WebUtil.Alert("请输入正确的格式！");
            }
        }
    }
}
